<?php
class News extends CI_Controller {
	function __construct() {
		parent::__construct ();
		$this->load->helper ( 'url' );
		$this->load->model ( 'Muser' );
	}
	
	function index() {
		redirect ( base_url () .'news/newsList' );
	}
	
	function newsList() {
		$this->load->model ( 'Mnews' );
		$this->load->library ( 'pagination' );
		
		$this->load->model ( 'Mabout' );
		$data ['uid'] = $this->session->userdata ( 'uid' );
		$data ['name'] = $this->session->userdata ( 'uname' );
		$data['cardAboutList']=$this->Mabout->getAboutListbyClass( 'C' );
		$data['aboutList']=$this->Mabout->getAboutListbyClass( 'A' );
		
		$data ['num'] = $this->Mnews->getNewsNum ();
		$data ['page'] = $this->uri->segment ( 3, 0 );
		
		$config ['base_url'] = base_url () . 'news/newsList/';
		$config ['total_rows'] = $data ['num'];
		$config ['per_page'] = PAGE_SHOW_NUM;
		$config ['uri_segment'] = 3;
		$config ['num_links'] = 2;
		$this->pagination->initialize ( $config );
		
		$data ['newslist'] = $this->Mnews->getNewsList ( $data ['page'], PAGE_SHOW_NUM );
		$data ['className'] = '纽斯达新闻';
		$data ['class'] = 'news';
		
		$this->load->view ( 'news_list', $data );
	}
	
	function newsContent() {
		$this->load->model ( 'Mabout' );
		$data ['uid'] = $this->session->userdata ( 'uid' );
		$data ['name'] = $this->session->userdata ( 'uname' );
		$data['cardAboutList']=$this->Mabout->getAboutListbyClass( 'C' );
		$data['aboutList']=$this->Mabout->getAboutListbyClass( 'A' );
		
		$this->load->helper ( 'string' );
		$id = $this->uri->segment ( 3, 0 );
		$this->load->model ( 'Mnews' );
		$data ['news'] = $this->Mnews->getItembyIdClass ( $id, 'N' );
		if ($data ['news']) {
			$data ['success'] = TRUE;
		} else
			$data ['success'] = FALSE;
		
		$data ['relatedList'] = $this->Mnews->getRelatedList ();
		
		$data ['className'] = '纽斯达新闻';
		$data ['class'] = 'news';
		$this->load->view ( 'news_content', $data );
	}
	
	function activityList() {
		$this->load->model ( 'Mabout' );
		$data ['uid'] = $this->session->userdata ( 'uid' );
		$data ['name'] = $this->session->userdata ( 'uname' );
		$data['cardAboutList']=$this->Mabout->getAboutListbyClass( 'C' );
		$data['aboutList']=$this->Mabout->getAboutListbyClass( 'A' );
		
		$this->load->model ( 'Mnews' );
		$this->load->library ( 'pagination' );
		
		$data ['num'] = $this->Mnews->getActivityNum ();
		$data ['page'] = $this->uri->segment ( 3, 0 );
		
		$config ['base_url'] = base_url () . 'news/activityList/';
		$config ['total_rows'] = $data ['num'];
		$config ['per_page'] = PAGE_SHOW_NUM;
		$config ['uri_segment'] = 3;
		$config ['num_links'] = 2;
		$this->pagination->initialize ( $config );
		
		$data ['newslist'] = $this->Mnews->getActivityList ( $data ['page'], PAGE_SHOW_NUM );
		
		$data ['className'] = '商户活动';
		$data ['class'] = 'activity';
		$this->load->view ( 'news_list', $data );
	}
	
	function activityContent() {
		$this->load->model ( 'Mabout' );
		$data ['uid'] = $this->session->userdata ( 'uid' );
		$data ['name'] = $this->session->userdata ( 'uname' );
		$data['cardAboutList']=$this->Mabout->getAboutListbyClass( 'C' );
		$data['aboutList']=$this->Mabout->getAboutListbyClass( 'A' );
		
		$this->load->helper ( 'string' );
		$id = $this->uri->segment ( 3, 0 );
		$this->load->model ( 'Mnews' );
		$data ['news'] = $this->Mnews->getItembyIdClass ( $id, 'A' );
		if ($data ['news']) {
			$data ['success'] = TRUE;
		} else
			$data ['success'] = FALSE;
		$data ['relatedList'] = $this->Mnews->getRelatedList ();
		$data ['className'] = '商户活动';
		$data ['class'] = 'activity';
		$this->load->view ( 'news_content', $data );
	}
	
	function cardPostList() {
		$this->load->model ( 'Mabout' );
		$data ['uid'] = $this->session->userdata ( 'uid' );
		$data ['name'] = $this->session->userdata ( 'uname' );
		$data['cardAboutList']=$this->Mabout->getAboutListbyClass( 'C' );
		$data['aboutList']=$this->Mabout->getAboutListbyClass( 'A' );
		
		$this->load->model ( 'Mnews' );
		$this->load->library ( 'pagination' );
		
		$data ['num'] = $this->Mnews->getCardPostNum ();
		$data ['page'] = $this->uri->segment ( 3, 0 );
		
		$config ['base_url'] = base_url () . 'news/cardPostList/';
		$config ['total_rows'] = $data ['num'];
		$config ['per_page'] = PAGE_SHOW_NUM;
		$config ['uri_segment'] = 3;
		$config ['num_links'] = 2;
		$this->pagination->initialize ( $config );
		
		$data ['newslist'] = $this->Mnews->getCardPostList ( $data ['page'], PAGE_SHOW_NUM );
		
		$data ['className'] = '卡片公告';
		$data ['class'] = 'cardPost';
		$this->load->view ( 'news_list', $data );
	}
	
	function cardPostContent() {
		$this->load->model ( 'Mabout' );
		$data ['uid'] = $this->session->userdata ( 'uid' );
		$data ['name'] = $this->session->userdata ( 'uname' );
		$data['cardAboutList']=$this->Mabout->getAboutListbyClass( 'C' );
		$data['aboutList']=$this->Mabout->getAboutListbyClass( 'A' );
		
		$this->load->helper ( 'string' );
		$id = $this->uri->segment ( 3, 0 );
		$this->load->model ( 'Mnews' );
		$data ['news'] = $this->Mnews->getItembyIdClass ( $id, 'C' );
		if ($data ['news']) {
			$data ['success'] = TRUE;
		} else
			$data ['success'] = FALSE;
		$data ['relatedList'] = $this->Mnews->getRelatedList ();
		$data ['className'] = '卡片公告';
		$data ['class'] = 'cardPost';
		$this->load->view ( 'news_content', $data );
	}
}